import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { resolve } from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    createSvgIconsPlugin({
      iconDirs: [resolve(process.cwd(), "src/assets/svg")],
      symbolId: "icon-[dir]-[name]",
    }),
    Components({
      dts: "src/components.d.ts",
      types: [{ from: "vue-router", names: ["RouterLink", "RouterView"] }],
      resolvers: [NaiveUiResolver()],
    }),
    AutoImport({
      dts: "src/auto-imports.d.ts",
      imports: ["vue", "vue-router"],
    }),
  ],

  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
  server: {
    open: true, //启动项目自动弹出浏览器
    port: 4000, //启动端口
    proxy: {
      "/api": {
        target: "http://localhost:8080", //实际请求地址
        changeOrigin: true,
      },
    },
  },
});
